
<!DOCTYPE HTML>
<html lang="en" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>二类消息 · smartboot 中文指南</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="5-type-three.html" />
    
    
    <link rel="prev" href="3-type-one.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"smartboot","repo":"smart-socket","type":"star","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    关于smartboot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    smart-socket 使用手册
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../quickStart.html">
            
                <a href="../quickStart.html">
            
                    
                    快速上手
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" >
            
                <span>
            
                    
                    源码篇
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="../first/1-ready.html">
            
                <a href="../first/1-ready.html">
            
                    
                    准备工作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="../first/2-core-interface.html">
            
                <a href="../first/2-core-interface.html">
            
                    
                    核心接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.3" data-path="../first/3-enum.html">
            
                <a href="../first/3-enum.html">
            
                    
                    枚举状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.4" data-path="../first/4-IoServerConfig.html">
            
                <a href="../first/4-IoServerConfig.html">
            
                    
                    服务配置IoServerConfig
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.5" data-path="../first/5-AioQuickServer.html">
            
                <a href="../first/5-AioQuickServer.html">
            
                    
                    服务端AioQuickServer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.6" data-path="../first/6-AioQuickClient.html">
            
                <a href="../first/6-AioQuickClient.html">
            
                    
                    客户端AioQuickClient
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.7" data-path="../first/7-AioSession.html">
            
                <a href="../first/7-AioSession.html">
            
                    
                    通信会话AioSession
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.8" data-path="../first/8-CompletionHandler.html">
            
                <a href="../first/8-CompletionHandler.html">
            
                    
                    读写回调
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.4" >
            
                <span>
            
                    
                    进阶篇
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.4.1" data-path="readme.html">
            
                <a href="readme.html">
            
                    
                    开篇概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.2" data-path="2-decoder.html">
            
                <a href="2-decoder.html">
            
                    
                    协议解码器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.3" data-path="3-type-one.html">
            
                <a href="3-type-one.html">
            
                    
                    一类消息
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.4.4" data-path="4-type-two.html">
            
                <a href="4-type-two.html">
            
                    
                    二类消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.5" data-path="5-type-three.html">
            
                <a href="5-type-three.html">
            
                    
                    三类消息
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.5" >
            
                <a target="_blank" href="https://smartboot.github.io/smart-socket/apidocs/index.html">
            
                    
                    API Docs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    smart-ioc 使用手册
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    smart-boot 使用手册
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    mydalgen 使用手册
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    技术分享
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../share/rpc/smart-socket-rpc.html">
            
                <a href="../../share/rpc/smart-socket-rpc.html">
            
                    
                    smart-socket实现RPC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../../share/exception/readme.html">
            
                <a href="../../share/exception/readme.html">
            
                    
                    Exception杂谈
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../../donation.html">
            
                <a href="../../donation.html">
            
                    
                    关于捐赠
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >二类消息</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x4E8C;&#x7C7B;&#x6D88;&#x606F;">&#x4E8C;&#x7C7B;&#x6D88;&#x606F;</h1>
<p>&#x91CD;&#x7533;&#x4E00;&#x4E0B;&#x201C;&#x4E8C;&#x7C7B;&#x6D88;&#x606F;&#x201D;&#x7684;&#x5B9A;&#x4E49;&#xFF1A;&#x957F;&#x5EA6;&#x8D85;&#x8FC7;&#x4E86;&#x9884;&#x5148;&#x4E3A;Socket&#x8FDE;&#x63A5;&#x5206;&#x914D;&#x7684;&#x8BFB;&#x7F13;&#x51B2;&#x533A;&#x5927;&#x5C0F;&#x7684;&#x6D88;&#x606F;&#xFF0C;&#x5373;readBufferSize:512byte&#xFF0C;&#x63A5;&#x6536;&#x5230;&#x7684;&#x5B9E;&#x9645;MessageSize:600byte&#x3002;&#x9488;&#x5BF9;&#x6B64;&#x7C7B;&#x6D88;&#x606F;&#xFF0C;&#x5728;&#x89E3;&#x7801;&#x65F6;&#x9700;&#x8981;&#x7533;&#x8BF7;&#x4E00;&#x4E2A;&#x8DB3;&#x591F;&#x5BB9;&#x91CF;&#x7684;&#x4E34;&#x65F6;&#x7F13;&#x51B2;&#x533A;&#x7528;&#x4E8E;&#x5B58;&#x653E;&#x5F53;&#x524D;&#x6D88;&#x606F;&#x7684;&#x5B57;&#x8282;&#x6570;&#x7EC4;&#x3002;</p>
<p>&#x7136;&#x800C;smart-socket&#x672C;&#x8EAB;&#x5E76;&#x4E0D;&#x63D0;&#x4F9B;&#x6269;&#x5BB9;&#x8BFB;&#x7F13;&#x5B58;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x662F;&#x7531;&#x4E8E;&#x6846;&#x67B6;&#x65E0;&#x6CD5;&#x8BC6;&#x522B;&#x6D88;&#x606F;&#x7684;&#x6709;&#x6548;&#x6027;&#xFF0C;&#x4E00;&#x65E6;&#x906D;&#x9047;&#x6076;&#x610F;&#x653B;&#x51FB;&#x6216;&#x8005;&#x7528;&#x6237;&#x6EE5;&#x7528;&#x53EF;&#x6269;&#x5BB9;&#x7684;&#x8BFB;&#x7F13;&#x51B2;&#x533A;&#xFF0C;&#x4F1A;&#x9020;&#x6210;&#x5185;&#x5B58;&#x65B9;&#x9762;&#x4E0D;&#x53EF;&#x9884;&#x77E5;&#x7684;&#x5F02;&#x5E38;&#x60C5;&#x51B5;&#x3002;smart-socket&#x5728;&#x8BBE;&#x8BA1;&#x4E4B;&#x521D;&#x4FBF;&#x975E;&#x5E38;&#x91CD;&#x89C6;&#x670D;&#x52A1;&#x7684;&#x7A33;&#x5B9A;&#x6027;&#xFF0C;&#x5BF9;&#x4E8E;&#x7528;&#x6237;&#x6280;&#x80FD;&#x6C34;&#x5E73;&#x7684;&#x8981;&#x6C42;&#x4E5F;&#x4F1A;&#x7565;&#x9AD8;&#x4E8E;&#x67D0;&#x4E9B;&#x540C;&#x7C7B;&#x901A;&#x4FE1;&#x6846;&#x67B6;&#xFF0C;&#x7531;&#x6B64;&#x4E5F;&#x5BFC;&#x81F4;smart-socket&#x7684;&#x4F7F;&#x7528;&#x4F53;&#x9A8C;&#x7A0D;&#x663E;&#x900A;&#x8272;&#x3002;&#x5982;&#x679C;&#x8981;&#x5728;&#x8FCE;&#x5408;&#x7528;&#x6237;&#x7684;&#x4F7F;&#x7528;&#x4F53;&#x9A8C;&#x4E0E;&#x670D;&#x52A1;&#x53EF;&#x9760;&#x6027;&#x4E4B;&#x95F4;&#x505A;&#x4E00;&#x4E2A;&#x9009;&#x62E9;&#xFF0C;smart-socket&#x9009;&#x62E9;&#x540E;&#x8005;&#x3002;&#x81F3;&#x4E8E;&#x5982;&#x4F55;&#x5904;&#x7406;&#x597D;&#x201C;&#x4E8C;&#x7C7B;&#x6D88;&#x606F;&#x201D;&#x7684;&#x7F16;&#x89E3;&#x7801;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E9B;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x4EE5;&#x4F9B;&#x53C2;&#x8003;&#x3002;</p>
<blockquote>
<p>&#x4EE5;&#x4E0B;&#x6848;&#x4F8B;&#x4F1A;&#x5BF9;&#x5B9E;&#x9645;&#x573A;&#x666F;&#x4E2D;&#x7684;&#x534F;&#x8BAE;&#x8FDB;&#x884C;&#x7B80;&#x5316;&#x5904;&#x7406;&#xFF0C;&#x65B9;&#x4FBF;&#x5927;&#x5BB6;&#x7406;&#x89E3;&#x3002;&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x8BFB;&#x7F13;&#x51B2;&#x533A;&#x8BBE;&#x5B9A;&#x4E3A;8&#x5B57;&#x8282;&#x3002;</p>
</blockquote>
<h3 id="&#x5B9A;&#x957F;&#x534F;&#x8BAE;">&#x5B9A;&#x957F;&#x534F;&#x8BAE;</h3>
<p>&#x534F;&#x8BAE;&#x683C;&#x5F0F;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x5B57;&#x6BB5;</th>
<th>&#x542B;&#x4E49;</th>
<th>&#x957F;&#x5EA6;</th>
</tr>
</thead>
<tbody>
<tr>
<td>length</td>
<td>&#x6D88;&#x606F;&#x5934;&#xFF0C;&#x5176;&#x503C;&#x8868;&#x793A;&#x6D88;&#x606F;&#x4F53;&#x957F;&#x5EA6;</td>
<td>4&#x5B57;&#x8282;</td>
</tr>
<tr>
<td>data</td>
<td>&#x6D88;&#x606F;&#x4F53;</td>
<td>length&#x503C;</td>
</tr>
</tbody>
</table>
<p>&#x6839;&#x636E;&#x4E0A;&#x8FF0;&#x534F;&#x8BAE;&#xFF0C;&#x5047;&#x8BBE;&#x5BA2;&#x6237;&#x7AEF;&#x53D1;&#x9001;&#x7684;&#x6D88;&#x606F;&#x4E3A;&#xFF1A;9abcdefjhi&#xFF0C;&#x7B2C;&#x4E00;&#x4F4D;&#x6D88;&#x606F;&#x5934;&#x201D;9&#x201C;&#x4E3A;int&#x7C7B;&#x578B;&#xFF0C;&#x5360;&#x7528;&#x4E86;4&#x5B57;&#x8282;&#xFF0C;&#x540E;&#x7EED;&#x7684;&#x6D88;&#x606F;&#x4F53;&#x201C;abcdefjhi&#x201D;&#x5360;&#x7528;&#x4E86;9&#x5B57;&#x8282;&#xFF0C;&#x6240;&#x4EE5;&#x670D;&#x52A1;&#x7AEF;&#x672C;&#x6B21;&#x6536;&#x5230;&#x7684;&#x6D88;&#x606F;&#x957F;&#x5EA6;&#x4E3A;&#xFF1A;13&#x5B57;&#x8282;&#x3002;&#x7531;&#x4E8E;&#x8BFB;&#x7F13;&#x51B2;&#x533A;&#x7684;&#x957F;&#x5EA6;&#x9650;&#x5236;&#x4E3A;8&#xFF0C;&#x5219;&#x201C;9abcd&#x201D;&#x4FBF;&#x586B;&#x6EE1;&#x4E86;&#x7F13;&#x51B2;&#x533A;&#xFF0C;&#x9700;&#x8981;&#x5148;&#x5C06;&#x5176;&#x8BFB;&#x53D6;&#x5B8C;&#x540E;&#x518D;&#x53BB;&#x8BFB;&#x201C;efjhi&#x201D;&#x3002;&#x7F16;&#x89E3;&#x7801;&#x7B97;&#x6CD5;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre><code>public class FixedLengthProtocol implements Protocol&lt;String&gt; {
    private static final int INT_BYTES = 4;//int&#x7C7B;&#x578B;&#x7684;&#x5B57;&#x8282;&#x957F;&#x5EA6;

    @Override
    public String decode(ByteBuffer readBuffer, AioSession&lt;String&gt; session, boolean eof) {
        if (session.getAttachment() == null &amp;&amp; readBuffer.remaining() &lt; INT_BYTES) {//&#x9996;&#x6B21;&#x89E3;&#x7801;&#x4E0D;&#x8DB3;&#x56DB;&#x5B57;&#x8282;&#xFF0C;&#x65E0;&#x6CD5;&#x77E5;&#x6653;&#x6D88;&#x606F;&#x957F;&#x5EA6;
            return null;
        }
        FixedLengthFrameDecoder fixedLengthFrameDecoder;
        if (session.getAttachment() != null) {
            fixedLengthFrameDecoder = (FixedLengthFrameDecoder) session.getAttachment();
        } else {
            int length = readBuffer.getInt();//&#x83B7;&#x5F97;&#x6D88;&#x606F;&#x4F53;&#x957F;&#x5EA6;
            fixedLengthFrameDecoder = new FixedLengthFrameDecoder(length);//&#x6784;&#x5EFA;&#x6307;&#x5B9A;&#x957F;&#x5EA6;&#x7684;&#x4E34;&#x65F6;&#x7F13;&#x51B2;&#x533A;
            session.setAttachment(fixedLengthFrameDecoder);//&#x7F13;&#x5B58;&#x4E34;&#x65F6;&#x7F13;&#x51B2;&#x533A;
        }

        if (!fixedLengthFrameDecoder.decode(readBuffer)) {
            return null;//&#x5DF2;&#x8BFB;&#x53D6;&#x7684;&#x6570;&#x636E;&#x4E0D;&#x8DB3;length&#xFF0C;&#x8FD4;&#x56DE;null
        }
        //&#x6570;&#x636E;&#x8BFB;&#x53D6;&#x5B8C;&#x6BD5;
        ByteBuffer fullBuffer = fixedLengthFrameDecoder.getBuffer();
        byte[] bytes = new byte[fullBuffer.remaining()];
        fullBuffer.get(bytes);
        session.setAttachment(null);//&#x91CA;&#x653E;&#x4E34;&#x65F6;&#x7F13;&#x51B2;&#x533A;
        return new String(bytes);
    }

    @Override
    public ByteBuffer encode(String msg, AioSession&lt;String&gt; session) {
        byte[] bytes = msg.getBytes();
        ByteBuffer buffer = ByteBuffer.allocate(INT_BYTES + bytes.length);
        buffer.putInt(bytes.length);//&#x6D88;&#x606F;&#x5934;
        buffer.put(bytes);//&#x6D88;&#x606F;&#x4F53;
        buffer.flip();
        return buffer;
    }
}
</code></pre><h3 id="&#x7279;&#x5B9A;&#x7ED3;&#x675F;&#x7B26;&#x534F;&#x8BAE;">&#x7279;&#x5B9A;&#x7ED3;&#x675F;&#x7B26;&#x534F;&#x8BAE;</h3>
<p>&#x534F;&#x8BAE;&#x683C;&#x5F0F;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x5B57;&#x6BB5;</th>
<th>&#x542B;&#x4E49;</th>
<th>&#x957F;&#x5EA6;</th>
</tr>
</thead>
<tbody>
<tr>
<td>data</td>
<td>&#x6D88;&#x606F;&#x4F53;</td>
<td>&#x672A;&#x77E5;</td>
</tr>
<tr>
<td>endFlag</td>
<td>&#x7ED3;&#x675F;&#x7B26;</td>
<td>endFlag&#x7684;&#x5B57;&#x8282;&#x957F;&#x5EA6;</td>
</tr>
</tbody>
</table>
<p>&#x76F8;&#x8F83;&#x4E8E;&#x5B9A;&#x957F;&#x534F;&#x8BAE;&#xFF0C;&#x6B64;&#x7C7B;&#x534F;&#x8BAE;&#x5728;&#x89E3;&#x7801;&#x7ED3;&#x675F;&#x4E4B;&#x524D;&#x90FD;&#x65E0;&#x6CD5;&#x77E5;&#x6653;&#x6D88;&#x606F;&#x7684;&#x957F;&#x5EA6;,&#x76F4;&#x5230;&#x8BFB;&#x53D6;&#x5230;&#x7ED3;&#x675F;&#x7B26;&#x6807;&#x5FD7;&#xFF0C;&#x5219;&#x6B64;&#x524D;&#x6240;&#x6709;&#x5DF2;&#x8BFB;&#x7684;&#x6570;&#x636E;&#x65B9;&#x53EF;&#x7EC4;&#x6210;&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x7684;&#x6D88;&#x606F;&#x6216;&#x6D88;&#x606F;&#x5B57;&#x6BB5;&#x3002;&#x4F8B;&#x5982;&#x6309;&#x884C;&#x53D1;&#x9001;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x6570;&#x636E;&#xFF1A;<code>abc\r\n123\r\n</code>&#xFF0C;&#x4EE5;<code>\r\n</code>&#x4F5C;&#x4E3A;&#x7ED3;&#x675F;&#x7B26;&#x53D1;&#x9001;&#x4E86;&#x4E24;&#x4E2A;&#x6D88;&#x606F;&#xFF1A;<code>abc</code>&#xFF0C;<code>123</code>&#x3002;</p>
<pre><code>public class DelimiterProtocol implements Protocol&lt;String&gt; {

    //&#x7ED3;&#x675F;&#x7B26;\r\n
    private static final byte[] DELIMITER_BYTES = new byte[]{&apos;\r&apos;, &apos;\n&apos;};

    @Override
    public String decode(ByteBuffer buffer, AioSession&lt;String&gt; session, boolean eof) {
        DelimiterFrameDecoder delimiterFrameDecoder;
        if (session.getAttachment() == null) {//&#x6784;&#x9020;&#x6307;&#x5B9A;&#x7ED3;&#x675F;&#x7B26;&#x7684;&#x4E34;&#x65F6;&#x7F13;&#x51B2;&#x533A;
            delimiterFrameDecoder = new DelimiterFrameDecoder(DELIMITER_BYTES, 64);
            session.setAttachment(delimiterFrameDecoder);//&#x7F13;&#x5B58;&#x89E3;&#x7801;&#x5668;&#x5DF2;&#x5E94;&#x5BF9;&#x534A;&#x5305;&#x60C5;&#x51B5;
        } else {
            delimiterFrameDecoder = (DelimiterFrameDecoder) session.getAttachment();
        }

        //&#x672A;&#x89E3;&#x6790;&#x5230;DELIMITER_BYTES&#x5219;&#x8FD4;&#x56DE;null
        if (!delimiterFrameDecoder.decode(buffer)) {
            return null;
        }
        //&#x89E3;&#x7801;&#x6210;&#x529F;
        ByteBuffer byteBuffer = delimiterFrameDecoder.getBuffer();
        byte[] bytes = new byte[byteBuffer.remaining()];
        byteBuffer.get(bytes);
        session.setAttachment(null);//&#x91CA;&#x653E;&#x4E34;&#x65F6;&#x7F13;&#x51B2;&#x533A;
        return new String(bytes);
    }

    @Override
    public ByteBuffer encode(String msg, AioSession&lt;String&gt; session) {
        byte[] bytes = msg.getBytes();
        ByteBuffer buffer = ByteBuffer.allocate(bytes.length + DELIMITER_BYTES.length);
        buffer.put(bytes).put(DELIMITER_BYTES);
        buffer.flip();
        return buffer;
    }
}
</code></pre><footer class="page-footer"><span class="copyright">Copyright &#xA9; smartboot.org 2018 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2018-08-10 15:08:12
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="3-type-one.html" class="navigation navigation-prev " aria-label="Previous page: 一类消息">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="5-type-three.html" class="navigation navigation-next " aria-label="Next page: 三类消息">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"二类消息","level":"1.2.4.4","depth":3,"next":{"title":"三类消息","level":"1.2.4.5","depth":3,"path":"smart-socket/second/5-type-three.md","ref":"smart-socket/second/5-type-three.md","articles":[]},"previous":{"title":"一类消息","level":"1.2.4.3","depth":3,"path":"smart-socket/second/3-type-one.md","ref":"smart-socket/second/3-type-one.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-sharing","search-plus","expandable-chapters-interactive","tbfed-pagefooter","github","github-buttons","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy smartboot.org 2018","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"github":{"url":"https://github.com/smartboot/smart-socket"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"expandable-chapters-interactive":{},"github-buttons":{"buttons":[{"user":"smartboot","repo":"smart-socket","type":"star","size":"small","count":true}]},"edit-link":{"label":"Edit This Page","base":"https://gitee.com/smartboot/docs/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"smartboot 中文指南","language":"en","gitbook":"*","description":"本文涵盖了smartboot下所有项目的技术手册"},"file":{"path":"smart-socket/second/4-type-two.md","mtime":"2018-08-10T07:08:12.495Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2018-09-23T08:59:34.607Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

